﻿using Acr.UserDialogs;
using Android.App;
using Android.Content.PM;
using Android.OS;
using HCAppBase.Android;
using LinnerToolkit.Core.Services;
using LinnerToolkit.Droid.Services;
using Prism;
using Prism.Ioc;


namespace TangReadyV1.Droid
{
    [Activity(Theme = "@style/MainTheme", Label = "UIAdaption", Icon = "@drawable/icon",
              ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)]
    public class MainActivity : MainActivityBase
    {

        /// <summary>
        /// 用于代替：Xamarin.Forms.Forms.Context
        /// </summary>
        internal static MainActivity Instance { get; private set; }

        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;

            UserDialogs.Init(this);
            Rg.Plugins.Popup.Popup.Init(this, savedInstanceState);
         //   FFImageLoading.Forms.Platform.CachedImageRenderer.Init(true);
            Resources.Configuration.FontScale = 1;
            //this.RequestedOrientation = Android.Content.PM.ScreenOrientation.Portrait;
            this.RequestedOrientation = Android.Content.PM.ScreenOrientation.Portrait;


            Initialize(savedInstanceState);   //very important 

            base.OnCreate(savedInstanceState);

            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);

            Instance = this;
            LoadApplication(new App(new AndroidInitializer()));
        }

    }

    public class AndroidInitializer : AndroidInitializerBase
    {
        public override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            base.RegisterTypes(containerRegistry);
            // Register any platform specific implementations

            containerRegistry.Register<INotifyService, NotifyService>();
            containerRegistry.RegisterInstance(UserDialogs.Instance);
            
        }
    }
}

